var a = function(a) {
    return a && a.__esModule ? a : {
        default: a
    };
}(require("../../utils/config.js")), t = require("../../utils/api.js"), e = require("../../utils/util.js"), s = (require("../../wxParse/wxParse.js"), 
require("../../utils/wxApi.js"), require("../../utils/wxRequest.js")), i = (getApp(), 
a.default.getPageCount);

Page({
    data: {
        title: "文章列表",
        postsList: {},
        pagesList: {},
        categoriesList: {},
        postsShowSwiperList: {},
        isLastPage: !1,
        page: 1,
        search: "",
        categories: 0,
        categoriesName: "",
        categoriesImage: "",
        showerror: "none",
        isCategoryPage: "none",
        isSearchPage: "none",
        showallDisplay: "block",
        displaySwiper: "block",
        floatDisplay: "none",
        searchKey: ""
    },
    formSubmit: function(a) {
        var t = "../list/list";
        "" != a.detail.value.input && (t = t + "?search=" + a.detail.value.input), wx.navigateTo({
            url: t
        });
    },
    onShareAppMessage: function() {
        var a = "分享“叶赫先生”", t = "";
        return this.data.categories && 0 != this.data.categories ? (a += "的专题：" + this.data.categoriesList.name, 
        t = "pages/list/list?categoryID=" + this.data.categoriesList.id) : (a += "的搜索内容：" + this.data.searchKey, 
        t = "pages/list/list?search=" + this.data.searchKey), {
            title: a,
            path: t,
            success: function(a) {},
            fail: function(a) {}
        };
    },
    onReachBottom: function() {
        var a = this;
        a.data.isLastPage ? console.log("最后一页") : (a.setData({
            page: a.data.page + 1
        }), console.log("当前页" + a.data.page), this.fetchPostsData(a.data));
    },
    reload: function(a) {
        var t = this;
        t.data.categories && 0 != t.data.categories && (t.setData({
            isCategoryPage: "block",
            showallDisplay: "none",
            showerror: "none"
        }), t.fetchCategoriesData(t.data.categories)), t.data.search && "" != t.data.search && t.setData({
            isSearchPage: "block",
            showallDisplay: "none",
            showerror: "none",
            searchKey: t.data.search
        }), t.fetchPostsData(t.data);
    },
    loadMore: function(a) {
        var t = this;
        t.data.isLastPage ? wx.showToast({
            title: "没有更多内容",
            mask: !1,
            duration: 1e3
        }) : (t.setData({
            page: t.data.page + 1
        }), console.log("当前页" + t.data.page), this.fetchPostsData(t.data));
    },
    onLoad: function(a) {
        var t = this;
        a.categoryID && 0 != a.categoryID && (t.setData({
            categories: a.categoryID,
            isCategoryPage: "block"
        }), t.fetchCategoriesData(a.categoryID)), a.search && "" != a.search && (wx.setNavigationBarTitle({
            title: "搜索关键字：" + a.search,
            success: function(a) {}
        }), t.setData({
            search: a.search,
            isSearchPage: "block",
            searchKey: a.search
        }), this.fetchPostsData(t.data));
    },
    onShow: function(a) {},
    fetchPostsData: function(a) {
        var o = this;
        a || (a = {}), a.page || (a.page = 1), a.categories || (a.categories = 0), a.search || (a.search = ""), 
        1 === a.page && o.setData({
            postsList: []
        }), wx.showLoading({
            title: "正在加载",
            mask: !0
        }), s.getRequest(t.getPosts(a)).then(function(a) {
            200 === a.statusCode ? (a.data.length < i && o.setData({
                isLastPage: !0
            }), o.setData({
                floatDisplay: "block",
                showallDisplay: "block",
                postsList: o.data.postsList.concat(a.data.map(function(a) {
                    var t = a.date;
                    return null != a.category_name ? a.categoryImage = "../../images/topic.png" : a.categoryImage = "", 
                    null != a.post_thumbnail_image && "" != a.post_thumbnail_image || (a.post_thumbnail_image = "../../images/logo700.png"), 
                    a.date = e.cutstr(t, 10, 1), a;
                }))
            })) : "rest_post_invalid_page_number" == a.data.code ? o.setData({
                isLastPage: !0
            }) : wx.showToast({
                title: a.data.message,
                duration: 1500
            });
        }).catch(function() {
            1 == a.page ? o.setData({
                showerror: "block",
                floatDisplay: "none"
            }) : (wx.showModal({
                title: "加载失败",
                content: "加载数据失败,请重试.",
                showCancel: !1
            }), o.setData({
                page: a.page - 1
            }));
        }).finally(function() {
            wx.hideLoading();
        });
    },
    redictDetail: function(a) {
        var t = "../detail/detail?id=" + a.currentTarget.id;
        wx.navigateTo({
            url: t
        });
    },
    fetchCategoriesData: function(a) {
        var e = this;
        e.setData({
            categoriesList: []
        }), s.getRequest(t.getCategoryByID(a)).then(function(a) {
            var t = "";
            t = void 0 === a.data.category_thumbnail_image || "" == a.data.category_thumbnail_image ? "../../images/website.png" : a.data.category_thumbnail_image, 
            e.setData({
                categoriesList: a.data,
                categoriesImage: t,
                categoriesName: a.data.name
            }), wx.setNavigationBarTitle({
                title: a.data.name,
                success: function(a) {}
            }), e.fetchPostsData(e.data);
        });
    }
});